﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WoWTimer.Classes
{
    public class Battle : IComparable
    {
        #region Fields

        string _type;
        string _realm;
        string _faction;
        DateTime _time;

        #endregion

        #region Construction

        public Battle(string type, string realm, string faction, long seconds)
        {
            _type = type;
            _realm = realm;
            _faction = faction;

            long ticks = secondsToTicks(seconds);
            DateTime dayZeroWoW = new DateTime(1970, 1, 1);

            _time = new DateTime(dayZeroWoW.Ticks + ticks);
            TimeSpan utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
            _time = _time.AddTicks(utcOffset.Ticks);
        }

        #endregion

        #region Properties

        public string Type
        {
            get { return _type; }
        }

        public string Realm
        {
            get { return _realm; }
        }

        public string Faction
        {
            get { return _faction; }
        }

        public DateTime Time
        {
            get { return _time; }
        }

        long secondsToTicks(long seconds)
        {
            return seconds * 10000000;
        }

        public override string ToString()
        {
            return _time.ToShortTimeString() + " - " + _type + " on " + _realm + " - " + _faction + " controlled";
        }

        #endregion

        #region IComparable Member

        public int CompareTo(object obj)
        {
            if (obj == null)
                return -1;

            Battle other = obj as Battle;
            if (other == null)
                return -1;

            if (this.Time > other.Time)
                return 1;
            else if (this.Time < other.Time)
                return -1;
            else return 0;
        }

        #endregion
    }
}
